﻿using System;
using System.Net;

using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace AudioTester.WaveStreams
{
    public class WaveStream : Stream
    {
        public WaveStream(IEnumerator<byte> datagGnerator)
        {
            _datagGnerator = datagGnerator;
        }


        IEnumerator<byte> _datagGnerator;
        public override bool CanRead
        {
            get { return true; }
        }

        public override bool CanSeek
        {
            get { return false; }
        }

        public override bool CanWrite
        {
            get { return false; }
        }

        public override void Flush()
        {
            throw new NotImplementedException();
        }

        public override long Length
        {
            get { return long.MaxValue; }
        }

        public override long Position
        {
            get;
            set;
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            for (int i = 0; i < count; i++)
            {
                var position = offset + i;
                if (_datagGnerator.MoveNext())
                {
                    buffer[position] = _datagGnerator.Current;
                }
                else
                {
                    throw new Exception("datagGnerator error");
                }
            }

            return count;
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotImplementedException();
        }

        public override void SetLength(long value)
        {
            throw new NotImplementedException();
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            throw new NotImplementedException();
        }



    }
}
